package guard_grammar;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import model.ProgramGraph;

/**
 * @version 1.0
 * @author Zlatka Trajcheska, Marija Petovska
 *
 * This class is supposed to parse and evaluate the restriction strings.
 */
public class RestrictionEvaluation {

	/**
	 * The name of the file which contains the restriction strings.
	 */
	private String filename;
	
	
	/**
	 * Constructor of the class.
	 * 
	 * @param fileName - The name of the file which contains the restriction strings
	 */
	public RestrictionEvaluation(String fileName) 
	{
		filename=fileName;
	}
	
	/**
	 * This method is supposed to read and parse the file with the restrictions.
	 * Also, this method fills in the restriction strings for the transitions in 
	 * the transition hash table.
	 * 
	 * @throws IOException
	 */
	public void checkRestriction(ProgramGraph programGraph) throws IOException
	{
		BufferedReader read = new BufferedReader(new FileReader(filename));
		
		String line;
		while((line=read.readLine())!=null)
		{
			String[] parts = line.split("=>");
			System.out.println("Transition "+parts[1]);
			System.out.println("Boolean expression: "+parts[0]);
			programGraph.addTransitionRestriction(parts[1], parts[0]);
		}
		
		read.close();
	}
}
